﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNA.Mvc.Installation;

namespace DNA.Mvc.Community.Installation
{
    public class ForumInstaller : InstallerBase
    {
        private IForumContext dbContext;

        public ForumInstaller(IForumContext forumContext)
        {
            dbContext = forumContext;
        }

        public override string Name
        {
            get { return "forums"; }
        }

        public override void Execute(InstallationContext context)
        {
            var topGroup = new Forum()
            {
                IsGroup = true,
                Title = "General discussion"
            };

            dbContext.Forums.Create(topGroup);
            dbContext.SaveChanges();

            var annForum = new Forum()
            {
                Title = "Announcements",
                Description = "The announcements of forum site",
                AllowAnonymous = true,
                IsModerated = true,
                IsLocked = true,
                ParentID = 0,
            };
            dbContext.Forums.Create(annForum);

            var genForum = new Forum()
            {
                AllowAnonymous = true,
                Title = "General",
                Description = "The general topics to discuss.",
                ParentID = topGroup.ID
            };
            dbContext.Forums.Create(genForum);

            var faqForum = new Forum()
            {
                Title = "FAQ",
                Description = "Questions and answers of the community site.",
                AllowAnonymous = true,
                ParentID = topGroup.ID
            };
            dbContext.Forums.Create(faqForum);
            dbContext.SaveChanges();

            for (var i = 0; i < 7; i++)
            {
                var rank = new Rank()
                {
                    IsStart = i == 0,
                    ImageUrl = "%theme%images/forums/icon_rank" + i.ToString() + ".png",
                    MinimumPosts = 100 * i
                };

                switch (i)
                {
                    case 0:
                        rank.Name = "Member";
                        break;
                    case 1:
                        rank.Name = "Helper";
                        break;
                    case 2:
                        rank.Name = "Participant";
                        break;
                    case 3:
                        rank.Name = "Contributor";
                        break;
                    case 4:
                        rank.Name = "Tutor";
                        break;
                    case 5:
                        rank.Name = "Expert";
                        break;
                    case 6:
                        rank.Name = "Scholar";
                        break;
                }

                dbContext.Ranks.Create(rank);
            }
            dbContext.SaveChanges();
        }
    }
}
